package com.tianyalei.wolf.sample.activity.wxcircle.widget.dialog;

import android.content.Context;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.TextView;

import com.tianyalei.wolf.sample.R;
import com.tianyalei.wolf.sample.activity.wxcircle.bean.CommentItem;
import com.tianyalei.wolf.sample.activity.wxcircle.data.DatasUtil;
import com.tianyalei.wolf.sample.activity.wxcircle.mvp.presenter.CirclePresenter;
import com.tianyalei.wolf.sample.view.BaseDialog;


/**
 * 
* @ClassName: CommentDialog 
* @Description: 评论长按对话框，保护复制和删除 
* @author yiw
* @date 2015-12-28 下午3:36:39 
*
 */
public class CommentDialog extends BaseDialog implements
		View.OnClickListener {

	private Context mContext;
	private CirclePresenter mPresenter;
	private CommentItem mCommentItem;
	private int mCirclePosition;

	public CommentDialog(Context context, CirclePresenter presenter,
						 CommentItem commentItem, int circlePosition) {
		super(context, R.style.base_dialog);
		mContext = context;
		this.mPresenter = presenter;
		this.mCommentItem = commentItem;
		this.mCirclePosition = circlePosition;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.copyTv:
			if (mCommentItem != null) {
				ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
				clipboard.setText(mCommentItem.getContent());
			}
			dismiss();
			break;
		case R.id.deleteTv:
			if (mPresenter != null && mCommentItem != null) {
				mPresenter.deleteComment(mCirclePosition, mCommentItem.getId());
			}
			dismiss();
			break;
		default:
			break;
		}
	}

	@Override
	protected int setLayoutView() {
		return R.layout.dialog_comment;
	}

	@Override
	protected void init(View mDialogView) {
		TextView copyTv = (TextView) findViewById(R.id.copyTv);
		copyTv.setOnClickListener(this);
		TextView deleteTv = (TextView) findViewById(R.id.deleteTv);
		if (mCommentItem != null
				&& DatasUtil.curUser.getId().equals(
				mCommentItem.getUser().getId())) {
			deleteTv.setVisibility(View.VISIBLE);
		} else {
			deleteTv.setVisibility(View.GONE);
		}
		deleteTv.setOnClickListener(this);
	}
}
